﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace LearnCSharp 
{
    class Indexeur : IEnumerator
    {
        static void Main2(string[] args)
        {            
            Indexeur oIndex = new Indexeur();
            oIndex.Read();

            //oIndex[1] = "lulu";
            for(int i=0; i<oIndex.Length; i++)
            {
                for(int j=0; j<oIndex[i].Length; j++)
                {
                    for(int k=0; k<oIndex[i][j].Length; k++)
                    {
                        Console.WriteLine("Index : {0}", oIndex[i][j][k]);
                    }
                }
            }
            /*
            foreach( string strSheet in oIndex )
            {
                Console.WriteLine("Index : {0}", strSheet);
            }
            */
            Console.ReadLine();
        }

        Sheet[] tabSheet;

        public class Sheet
        {
            public class Line
            {
                public string[] tab;

                public Line()
                {
                }

                public Line(int n)
                {
                    tab = new string[n];
                }

                public Line( params string[] E )
                {
                    tab = new string[E.Length];
                    for( int i=0; i<E.Length; i++) tab[i] = E[i];
                }               

                public string this[int n]
                {
                    get {return tab[n];}
                    set {tab[n] = value;}
                }

                public int this[string strName]
                {
                    get
                    {
                        for( int i=0; i<tab.Length; i++)
                        {
                            if(tab[i] == strName) return i;
                        }
                        return -1;
                    }
                }

                public int Length
                {
                    get
                    {
                        return tab.Length;
                    }
                }
            }

            public string strName;
            public Line[] tab;

            public Sheet()
            {
                strName = "";
            }

            public Sheet( params Line[] E )
            {
                tab = new Line[E.Length];
                for( int i=0; i<E.Length; i++) tab[i] = E[i];
            }               

            public Line this[int n]
            {
                get {return tab[n];}
                set {tab[n] = value;}
            }
            /*
            public int this[string strName]
            {
                get
                {
                    for( int i=0; i<tab.Length; i++)
                    {
                        if(Line[i] == strName) return i;
                    }
                    return -1;
                }
            }
            */
            public int Length
            {
                get
                {
                    return tab.Length;
                }
            }
        }

        public void Read()
        {
            tabSheet =  new Sheet[1];
            tabSheet[0] = new Sheet();

            tabSheet[0].tab = new LearnCSharp.Indexeur.Sheet.Line[3];

            tabSheet[0][0] = new LearnCSharp.Indexeur.Sheet.Line(1);
            tabSheet[0][1] = new LearnCSharp.Indexeur.Sheet.Line(2);
            tabSheet[0][2] = new LearnCSharp.Indexeur.Sheet.Line(3);
     
            tabSheet[0][0][0] = "000";
            tabSheet[0][1][0] = "010";
            tabSheet[0][1][1] = "011";
            tabSheet[0][2][0] = "020";
            tabSheet[0][2][1] = "021";
            tabSheet[0][2][2] = "022";
        }

        public Indexeur(params Sheet[] E)
        {
            tabSheet = new Sheet[E.Length];
            for( int i=0; i<E.Length; i++) tabSheet[i] = E[i];
        }

        public Sheet this[int n]
        {
            get {return tabSheet[n];}
            set {tabSheet[n] = value;}
        }

        public int this[string strName]
        {
            get
            {
                for( int i=0; i<tabSheet.Length; i++)
                {
                    if(tabSheet[i].strName == strName) return i;
                }
                return -1;
            }
        }

        public int Length
        {
            get
            {
                return tabSheet.Length;
            }
        }

        /////////////////////////////////////////////////////

        int index=-1;
        public IEnumerator GetEnumerator(){index=-1;return this;}
        public bool MoveNext(){return ++index<tabSheet.Length;}
        public void Reset(){index=-1;}
        public object Current
        {
            get{return tabSheet[index];}
        }
    }
}
